<!-- 案件详情——定时跟进表单 -->
<template>
	<s-table
		ref="tableRef"
		size="5"
		:pageSizeOptions="['5', '10', '20']"
		:columns="columns"
		:data="loadData"
		:scroll="{ x: 'max-content' }"
	>
		<template #bodyCell="{ column, record }">
			<template v-if="column.dataIndex === 'action'">
				<a-space>
					<a-button type="link" primary size="small" @click="editTrace(record)"> 修改 </a-button>
				</a-space>
				<a-popconfirm title="确定要删除此跟进吗？" @confirm="deleteTrace(record)">
					<a-button type="link" danger primary size="small"> 删除 </a-button>
				</a-popconfirm>
			</template>
		</template>
	</s-table>
</template>
<script setup name="timingFollow">
	import timingTraceApi from '@/api/tjzy/timingTrace/timingTraceApi.js'
	import tool from '@/utils/tool'

	const emit = defineEmits({ editliaisonSelfEvent: Object })
	const tableRef = ref()
	const columns = [
		{
			title: '客户姓名',
			dataIndex: 'traceName'
		},
		{
			title: '提醒时间',
			dataIndex: 'nextTraceTime'
		},
		{
			title: '提醒内容',
			dataIndex: 'traceRemark',
			ellipsis: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center'
		}
	]
	const props = defineProps({
		liaisonSelf: { type: Object, default: () => {} }
	})
	const userInfo = tool.data.get('USER_INFO')
	let searchFormState = ref({})
	const loadData = (parameter) => {
		const data = {
			current: parameter.current,
			size: parameter.size,
			createUser: userInfo.id,
			traceUser: props.liaisonSelf.id
		}
		return timingTraceApi.pageTracePlan(data).then((res) => {
			return res
		})
	}
	// 编辑定时跟进
	const editTrace = (record) => {
		emit('editliaisonSelfEvent', { ...record, _t: Date.now() }) //时间戳用于编辑同一条跟进记录时，触发相关监听的更新
		// return timingTraceApi.editTracePlan(searchFormState.value).then((res) => {
		// 	console.log('res', res)
		// 	return res
		// })
	}
	// 删除定时跟进
	const deleteTrace = (record) => {
		timingTraceApi.deleteTracePlan(record.id).then(() => {
			tableRefresh()
		})
	}
	//列表刷新
	const tableRefresh = () => {
		tableRef.value.refresh(false)
	}
	defineExpose({
		tableRefresh
	})
</script>
